//
//  StatusCell.swift
//  个人微博
//
//  Created by guo3920591 on 16/4/21.
//  Copyright © 2016年 guo3920591. All rights reserved.
//

import UIKit

class StatusCell: UITableViewCell {
   
    /// 微博视图模型
    var viewModel: StatusViewModel?{
        
        didSet{
            //设置数据
            
            originalView.viewModel = viewModel
            
            rexmontentView.viewModel = viewModel
            
        }
    }
    
    

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
// MARK: - 私有控件
    /// 原创微博
    private let originalView: StatusOriginalView = StatusOriginalView()
    /// 转发微博
    private let rexmontentView: StatusReccomentView = StatusReccomentView()
    /// 工具栏
    private let toolBar: StatusToolsView = StatusToolsView()


}
// MARK: - 设置界面
extension StatusCell {
    
    private func setupUI(){
        //1设置背景色
        backgroundColor = GXLcellColor
        
        //2添加控件
        
        contentView.addSubview(originalView)
        
        contentView.addSubview(rexmontentView)
        
        contentView.addSubview(toolBar)
        
        
       
        
        //3自动布局
        
        originalView.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(contentView)
            make.top.equalTo(contentView).offset(10)
            make.right.equalTo(contentView)
         
      }
        
        rexmontentView.snp_makeConstraints(closure: { (make) -> Void in
            
            make.left.equalTo(contentView)
            make.right.equalTo(contentView)
            make.top.equalTo(originalView.snp_bottom)
            
        })
        
        
        toolBar.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(contentView)
            make.right.equalTo(contentView)
            make.top.equalTo(rexmontentView.snp_bottom)
            make.height.equalTo(36)
            
            
        }
        
        //contenview的布局 //在动态加载cell的高度不同时 必须制定contenview的布局
        //必须指定contenview的底部约束 和 最下面控件的参照
        
        contentView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self)
            make.left.equalTo(self)
            make.right.equalTo(self)
            make.bottom.equalTo(toolBar)
        }
        
        //5异步绘制
        self.layer.drawsAsynchronously = true
        
        //6 栅格化 会将cell的图层内容生成一张图项并且缓存，在滚动中不再生成cell的内容
        self.layer.shouldRasterize = true
        
        //一定设置分辨率
        self.layer.rasterizationScale = UIScreen.mainScreen().scale
        
        
    }
    
    
}
